package com.fbli.Thread.Homework;

import java.util.Random;
import java.util.Scanner;

public class Homework01 {
    public static void main(String[] args) {
        T1 t1 = new T1();
        T2 t2 = new T2(t1);
        new Thread(t1).start();
        new Thread(t2).start();
    }
}
class T1 implements Runnable{
    public void setPool(boolean pool) {
        this.pool = pool;
    }

    private boolean pool = true;

    @Override
    public void run() {
        while (pool){
            Random random = new Random();
            int i = random.nextInt(100);
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class T2 implements Runnable{
    private T1 a;
    public T2(T1 a){
        this.a = a;
    }
    Scanner scanner = new Scanner(System.in);
    @Override
    public void run() {
        while (true){
            System.out.println("请输入你的指定（Q）退出");
            char key = scanner.next().toUpperCase().charAt(0);
            if ('Q' == key){
                a.setPool(false);
                break;
            }
        }
    }
}